﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace Himp.Platform.Dc.EntityFrameworkCore;

[DependsOn(
    typeof(DcDomainModule),
    typeof(AbpEntityFrameworkCoreModule)
)]
public class DcEntityFrameworkCoreModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<DcDbContext>(options =>
        {
            /* Add custom repositories here. Example:
             * options.AddRepository<Question, EfCoreQuestionRepository>();
             */
            options.AddDefaultRepositories(includeAllEntities: true);

            options.Entity<StdWordDict>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q; };
            });

            options.Entity<ChrgitmType>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q.Include(p => p.ChrgitmTypeGrp); };
            });
        });
    }
}
